package com.niit.session15;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Valid {
	public static final String EMAIL = "[a-zA-Z0-9]+@[a-zA-Z0-9]+.[a-zA-Z0-9]+";
	public static final String PHONE = "^1[3-9]\\d{9}";
	/**
	 * 验证邮箱是否符合规范
	 * @param email 要验证的邮箱
	 * @return
	 */
	public static boolean validEmail(String email) {
		Pattern compile = Pattern.compile(EMAIL);
		Matcher matcher = compile.matcher(email);
		boolean matches = matcher.matches();
		return matches;
	}
	
	/**
	 * 验证手机号是否符合规范
	 * @param phone 要验证的手机号
	 * @return
	 */
	public static boolean validPhone(String phone) {
		Pattern compile = Pattern.compile(PHONE);
		Matcher matcher = compile.matcher(phone);
		boolean matches = matcher.matches();
		return matches;
	}
}
